//
//  ZYCTeaAttendanceRecordBottomView.m
//  ZDSC
//
//  Created by 张威 on 2021/10/19.
//

#import "ZYCTeaAttendanceRecordBottomView.h"
#import "ZYCCustomButton.h"
#import "UIView+Gt.h"
@interface ZYCTeaAttendanceRecordBottomView ()

@property (nonatomic, strong) ZYCCustomButton *leftButton;
@property (nonatomic, strong) ZYCCustomButton *rightButton;
@property (nonatomic, strong) UIView *line;
@end


@implementation ZYCTeaAttendanceRecordBottomView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self addSubview:self.leftButton];
        [self addSubview:self.rightButton];
        [self addSubview:self.line];
        
        [self.leftButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.top.bottom.equalTo(self);
            make.width.mas_equalTo(CGSizeMake(self.width / 2,49.0f));
        }];
        
        [self.rightButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.top.equalTo(self);
            make.size.mas_equalTo(CGSizeMake(self.width / 2 , 49.0f));
        }];
        
        [self.line mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.bottom.equalTo(self);
            make.size.mas_equalTo(CGSizeMake(self.width / 2 , 2.5f));
        }];
    }
    return self;
}


- (ZYCCustomButton *)leftButton {
    if (!_leftButton) {
        _leftButton = [[ZYCCustomButton alloc] init];
        _leftButton.titleLab.text = @"打卡";
        _leftButton.tag = 1000;
        _leftButton.iconView.image = [UIImage imageNamed:@"dk"];
        _leftButton.titleLab.textColor = HEX_RGB(@"#49B46C");
        [_leftButton addTarget:self action:@selector(clickButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _leftButton;
}


- (ZYCCustomButton *)rightButton {
    if (!_rightButton) {
        _rightButton = [[ZYCCustomButton alloc] init];
        _rightButton.titleLab.text = @"统计";
        _rightButton.tag = 1001;
        _rightButton.iconView.image = [UIImage imageNamed:@"tj-2"];
        _rightButton.titleLab.textColor = HEX_RGB(@"#999999");
        [_rightButton addTarget:self action:@selector(clickButtonAction:) forControlEvents:UIControlEventTouchUpInside];

    }
    return _rightButton;
}

- (UIView *)line {
    if (!_line) {
        _line = [[UIView alloc] init];
        _line.backgroundColor = HEX_RGB(@"#49B46C");
    }
    return _line;
}

- (void)clickButtonAction:(ZYCCustomButton *)sender{
    sender.titleLab.textColor = HEX_RGB(@"#49B46C");
    if (sender.tag == 1000) {//左边
        sender.iconView.image = [UIImage imageNamed:@"dk"];
        self.rightButton.titleLab.textColor = HEX_RGB(@"#999999");
        self.rightButton.iconView.image = [UIImage imageNamed:@"tj-2"];
        
        [UIView animateWithDuration:0.3 animations:^{
            [self.line mas_remakeConstraints:^(MASConstraintMaker *make) {
                make.left.bottom.equalTo(self);
                make.size.mas_equalTo(CGSizeMake(self.width / 2 , 2.5f));
            }];
        } completion:nil];

    }else{//右边
        sender.iconView.image = [UIImage imageNamed:@"tjj"];
        self.leftButton.titleLab.textColor = HEX_RGB(@"#999999");
        self.leftButton.iconView.image = [UIImage imageNamed:@"dkk"];
        
        [UIView animateWithDuration:0.3 animations:^{
            [self.line mas_remakeConstraints:^(MASConstraintMaker *make) {
                make.right.bottom.equalTo(self);
                make.size.mas_equalTo(CGSizeMake(self.width / 2 , 2.5f));
            }];
        } completion:nil];
        

    }
    
    if ([self.delegate respondsToSelector:@selector(teaAttendanceRecordBottomViewDidClick:)]) {
        [self.delegate teaAttendanceRecordBottomViewDidClick:sender.tag - 1000];
    }
    
    
    
}
@end
